home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
misc_pto
/
linktext
/
linktext.doc
next >
Wrap
Text File
|
1989-03-20
|
1KB
|
21 lines
Writing your own editor? These Turbo Pascal routines may get you started.
When handling text files in Turbo Pascal, it is convinient to read the file
into an array of strings. While this may be fine for some applications,
the array size is limited by the 64K data segment that must be shared with
other variables. Another way to buffer text is to allocate memory
dynamically from the heap using GetMem.
My sample program LinkText.PAS demonstrates how to read a text file into a
singly linked list. Each element in the list contains a string and a
pointer to the next element. The "Head" record is actually a dummy element,
which contains only a pointer field that always points to the first real
element in the list. Notice that we must allocate 5 bytes more than the
length of the string. This allows for the length byte of the string and
the 4 bytes required for the pointer field.
The procedure DisplayFile traverses the list from top to bottom and writes
each line of the list. The DeleteLine and InsertLine procedures show how
to insert and delete records from this type of list by changing pointers.
--- Michael A. Reeder; Beaumont, Texas